package org.x.usermod.controller;

import cn.dev33.satoken.stp.StpUtil;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.x.commonmod.config.BusinessException;
import org.x.commonmod.config.Result;
import org.x.commonmod.enums.LogAsync;
import org.x.usermod.dto.LoginDTO;
import org.x.usermod.service.ISysUserService;
import org.x.usermod.vo.LoginVO;

@RestController
@RequestMapping("/api/auth")
public class SysLoginController {

    @Autowired
    private ISysUserService ISysUserService;
    @LogAsync("登录")
    @PostMapping("/login")
    public Result login(@Valid @RequestBody LoginDTO loginDTO) throws BusinessException {
        LoginVO loginVO = ISysUserService.login(loginDTO);
        return Result.ok(loginVO);
    }
    @PostMapping("/logout")
    public Result logout(@RequestParam Long id) {
        StpUtil.logout(id);
        return Result.ok("退出成功");
    }
}
